#include"mylist.h"
struct Node* list = createList();
struct Node* pMove = NULL;
void menu()
{
	printf("************学生信息管理系统************\n");
	printf("*********\t1.录入信息\t********\n");
	printf("*********\t2.浏览信息\t********\n");
	printf("*********\t3.修改信息\t********\n");
	printf("*********\t4.删除信息\t********\n");
	printf("*********\t5.查找信息\t********\n");
	printf("*********\t0.退出系统\t********\n");
	printf("****************************************\n");
}
void keydown()
{
	int choice = 0;
	struct student data;
	scanf("%d", &choice);
	switch (choice)
	{
	case 1:
		printf("*********\t1.录入信息\t********\n");
		printf("请输入学生的学号，姓名，年龄，性别，电话：");
		fflush(stdin);
		scanf("%s%s%d%s%s\0",data.num, data.name, &data.age, data.sex, data.tel);
		insertNodeByHead(list,data);
		break;
	case 2:
		printf("*********\t2.浏览信息\t********\n");
		printList(list);
		break;
	case 3:
		printf("*********\t3.修改信息\t********\n");
		changestu(list);
		break;
	case 4:
		printf("*********\t4.删除信息\t********\n");
		printf("请输入要删除的学生的姓名");
		scanf("%s", data.name);
		deleteAppoinNode(list,data.name);
		break;
	case 5:
		printf("*********\t5.查找信息\t********\n");
		printf("请输入要查找的学生姓名");
		scanf("%s", data.name);
		if (searchInfoByData(list, data.name) == NULL)
		{
			printf("未找到相关学生");
		}
		else
		{
			pMove = searchInfoByData(list, data.name);
			printf("学号\t姓名\t年龄\t性别\t电话\n");
			printf("%s\t%s\t%d\t%s\t%s\n", pMove->data.num,pMove->data.name, pMove->data.age, pMove->data.sex, pMove->data.tel);
		}
		break;
	case 0:
		printf("正常退出");
		system("pause");
		exit(0);
		break;
	default:
		printf("选择错误，重新选择");
		system("pause");
		break;
	}
	writeInfoFromFile(list, "1.txt");
}
int main()
{
	readInfoFromFile(list, "1.txt");
	while (1)
	{
		menu();
		keydown();
		system("pause");
		system("cls");
	}
	system("pause");
	return 0;
}
